package cn.tedu.csmall.server.preload;

import cn.tedu.csmall.server.mapper.BrandMapper;
import cn.tedu.csmall.server.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.server.repo.IBrandRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 缓存预热
 *  由于另外使用了计划任务(执行频率fixedRate的计划任务首次执行是在启动项目后)
 *  所以不需要此类实现缓存预热
 */
//@Component
@Slf4j
public class CachePreload implements ApplicationRunner {
    @Autowired
    private IBrandRepository brandRepository;
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.debug("执行CachePreload.run方法");

        List<BrandListItemVO> list = brandMapper.list();
        brandRepository.deleteList();
        brandRepository.putList(list);
    }
}
